package com.bot.nft.module.op.api;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bot.auth.core.pojo.SaBaseClientLoginUser;
import com.bot.auth.core.util.StpClientLoginUserUtil;
import com.bot.common.pojo.CommonResult;
import com.bot.nft.module.dc.domain.vo.DcNftCertVo;
import com.bot.nft.module.op.controller.OpSynController;
import com.bot.nft.module.op.domain.bo.DcCertQuery;
import com.bot.nft.module.op.domain.bo.OpSynThesisBo;
import com.bot.nft.module.op.domain.vo.AutNftInfoVo;
import com.bot.nft.module.op.domain.vo.DcNftCerVo;
import com.bot.nft.module.op.domain.vo.OpSynCertListVo;
import com.bot.nft.module.op.service.ISynService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;


@RestController
@RequestMapping("/app/syn")
@CrossOrigin
public class AppSynController extends OpSynController {
    @Resource
    public ISynService iSynService;

    /**
     *
     * @param nftId
     * HttpServletRequest request
     * @return
     */
    @RequestMapping("/{nftId}/viewNftCert.do")
    public CommonResult<List<OpSynCertListVo>> queryCertList(@PathVariable String nftId) {
//        MbUserInfoVo mbUserInfo = ReqMbInfoUtils.getMbUserInfo(request);
//        String mbId = mbUserInfo.getId();

        SaBaseClientLoginUser clientLoginUser = StpClientLoginUserUtil.getClientLoginUser();
        String mbId = clientLoginUser.getId();



        List<OpSynCertListVo> synRaw = iSynService.getSynRaw(mbId, nftId);
        return CommonResult.data(synRaw);
    }
    /**
     * 合成藏品功能
     *
     * @param thesisBo 合成藏品请求体
     * @return
     */
    @RequestMapping("/synThesis.do")
    public CommonResult<DcNftCertVo> synThesis(@RequestBody OpSynThesisBo thesisBo,HttpServletRequest request) {
        SaBaseClientLoginUser clientLoginUser = StpClientLoginUserUtil.getClientLoginUser();
        String mbId = clientLoginUser.getId();
        thesisBo.setMbId(mbId);
        //调用合成藏品功能接口
        DcNftCertVo dcNftCertVo = iSynService.synThesis(thesisBo.getNftIdList(), thesisBo.getMbId(), thesisBo.getSynId());
        if (dcNftCertVo==null) {
            return CommonResult.error();
        }
        //把查出来的数据放入统一格式中
        CommonResult<DcNftCertVo> data = CommonResult.data(dcNftCertVo);

        return data;
    }
    @RequestMapping("/{pageNo}/{pageSize}/queryNftCert.do")
    public CommonResult<Page<DcNftCerVo>> queryList(@PathVariable Integer pageNo, @PathVariable Integer pageSize, @RequestBody DcCertQuery dcCertQuery) {
        SaBaseClientLoginUser clientLoginUser = StpClientLoginUserUtil.getClientLoginUser();
        String mbId = clientLoginUser.getId();
        dcCertQuery.setMbId(mbId);
        Page<DcNftCerVo> dcNftCertVoPageInfo = iSynService.queryNftCert( pageNo, pageSize, dcCertQuery);
        return CommonResult.data(dcNftCertVoPageInfo);
    }


    @RequestMapping("/{id}/getAutNft.do")
    public CommonResult<List<AutNftInfoVo>> getAutNft(@PathVariable String id) {
        SaBaseClientLoginUser clientLoginUser = StpClientLoginUserUtil.getClientLoginUser();
        String mbId = clientLoginUser.getId();
        List<AutNftInfoVo> autNft = iSynService.getAutNft(id,mbId);
        return CommonResult.data(autNft);
    }
}
